﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDir>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    model=new QFileSystemModel;

    model->setRootPath(QDir::currentPath());

    ui->treeView->setModel(model);
    ui->listView->setModel(model);
    ui->tableView->setModel(model);


}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
    ui->listView->setRootIndex(index);
    ui->tableView->setRootIndex(index);


    ui->label_filename->setText(model->fileName(index));

    int size=model->size(index)/1024;
    if(size>1024)
    {
        ui->label_filesize->setText(QString::asprintf("%.lf MB",size/1024.0));
    }
    else
    {
        ui->label_filesize->setText(QString::asprintf("%d KB",size));
    }

    ui->label_nodetype->setText(model->type(index));

    ui->checkBox->setChecked(model->isDir(index));

    ui->label_path->setText(model->filePath(index));

}
